package model;

import java.util.Vector;

import init.DBManagement;
import model.beans.AcademiaBean;

public class Academy {
	
	public static AcademiaBean instance( String str_academyCode ){
		AcademiaBean academy_retVal = null;
		String str_instance = 
			" select nombre "+
			" from	 basacab "+
			" where  clave = '"+str_academyCode+"' ";
		DBManagement database = new DBManagement();
	    database.executeQuery( str_instance );
	    if( database.getNumRows() == 1 ){
	    	academy_retVal = new AcademiaBean();
	    	academy_retVal.setCodigo(str_academyCode);
	    	academy_retVal.setNombre(database.getItem(0, 0));
	    }
	    database = null;
		return academy_retVal;
	}
	
	public static Vector list(String str_user){
		Vector vec_retVal = new Vector();
		String str_list = 
			" select au.ACADEMIA_TK, "+
			"		 nombre, "+
			"        rol "+
			" from	 basusar au "+
			"			  inner join basacab a "+
			"			  on a.clave = au.academia_tk "+
			" where au.maestro_tk = '"+ str_user +"'";
		DBManagement database = new DBManagement();
	    database.executeQuery( str_list );
	    for( int int_i = 0; int_i < database.getNumRows(); int_i++){
	    	AcademiaBean academy = new AcademiaBean();
	    	academy.setCodigo(database.getItem(int_i, 0));
	    	academy.setNombre(database.getItem(int_i, 1));
	    	academy.setDescripcion(database.getItem(int_i, 0) + " - " + database.getItem(int_i, 1));
	    	academy.setRol(database.getItem(int_i, 2));
	    	vec_retVal.add(academy);
	    }
		return vec_retVal;
	}
	
	public static String academySubject(String str_materiaTK){
		String str_query = " select academia_tk "+
									  " from basacmr " +
									  " where materia_tk='" + 	str_materiaTK+ "' ";
		String str_academyTK = null;
		DBManagement database = new DBManagement();
	    database.executeQuery( str_query );
	    if(database.getNumRows() > 0){
	    	str_academyTK = database.getItem(0, 0);
	    }
	    return str_academyTK;
	}
}
